﻿using System;
using UnityEngine;
using UnityEngine.Rendering;

namespace ZxcRP.Runtime.Renderers
{
    /// <summary>
    /// 渲染器类型
    /// </summary>
    public enum RendererType
    {
        /// <summary>
        /// Poly-Style渲染器
        /// </summary>
        Poly,
    }

    /// <summary>
    /// 渲染器抽象类，所有的渲染器都继承他
    /// </summary>
    public abstract class Renderer : IDisposable
    {
        protected ScriptableRenderContext m_Context;
        protected Camera m_Camera;
        protected CommandBuffer m_CmdBuffer = new CommandBuffer();

        public void Render(ScriptableRenderContext context, Camera camera)
        {
            m_Context = context;
            m_Camera = camera;
#if UNITY_EDITOR
            m_CmdBuffer.name = GetName();
#endif
            OnRender();
        }

        /// <summary>
        /// 所有渲染器需要实现这个方法
        /// </summary>
        protected abstract void OnRender();

        /// <summary>
        /// 获取渲染器的名字（主要用于debug）
        /// </summary>
        /// <returns></returns>
        protected virtual string GetName()
        {
            return string.Empty;
        }

        protected abstract void OnDispose();

        public void Dispose()
        {
            m_CmdBuffer?.Dispose();
            OnDispose();
        }
    }
}